package com.smartrodin.springbootrabbitmq.service;


import com.smartrodin.springbootrabbitmq.entity.MqSendFileLog;
import com.smartrodin.springbootrabbitmq.mapper.MqSendFileLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

@Service
public class TestService {

    @Autowired
    private MqSendFileLogMapper mqSendFileLogMapper;

    @Autowired
    private MqSendFileLogServiceImpl sendFileLogService;


    @Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void test() {
        MqSendFileLog fileLog = new MqSendFileLog();
        fileLog.setCreateTime("2020-11-30" );
        fileLog.setErrorMsg( "TestService类" );
        mqSendFileLogMapper.insert( fileLog );
        sendFileLogService.test();

        try {
            int i = 0;
            int a = 2;
            int c = a / i;
        } catch (Exception e) {
            e.printStackTrace();
            // 事务回滚TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            sendFileLogService.test2();
        }
    }
}
